package com.hlx.service.impl;

import com.hlx.mapper.ChatHistoryMapper;
import com.hlx.service.ChatHistoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@RequiredArgsConstructor
@Service
public class ChatHistoryServiceImpl implements ChatHistoryService {
	private final ChatHistoryMapper chatHistoryMapper;
	/**
	 * 保存会话id
	 * @param type
	 * @param chatId
	 */
	@Override
	public void save(String type, String chatId) {
		int count = chatHistoryMapper.selectByChatId(chatId);
		if (count > 0) {
			return;
		}
		chatHistoryMapper.save(type, chatId);
	}

	/**
	 * 获取业务类型的会话id
	 * @param type
	 * @return
	 */
	@Override
	public List<String> getChatIds(String type) {
		List<String> chatIds = chatHistoryMapper.selectByType(type);
		if (chatIds != null && !chatIds.isEmpty()) {
			return chatIds;
		}
		return List.of();
	}
}
